<?php
/**
 * Created by PhpStorm.
 * User: Mak
 * Date: 2016/4/6 0006
 * Time: 0:44
 */

namespace Admin\Model;
use Think\Model;

class TecInfoModel extends Model{
    protected $tableName = "tecinfo";

    protected $_auto = array(
        array('password', 'md5', 3, 'function'), // 对password字段在新增和编辑的时候使md5函数处理
    );

    // 得到所有教师表中的记录
    public function getList() {
        $ret = $this->order('deptid asc')->select();
        return $ret;
    }

    // 根据学号取得教师个人信息
    public function getItem($TecId){
        $condition['tecid'] = $TecId;
        $ret = $this->where($condition)->find();
        return $ret;
    }

    // 验证登陆，返回1-正确；0；密码错； -1：用户名错。
    public function checkUser($TecId, $password){
        $TecId      = trim($TecId);
        $password = trim($password);
        $TecId = htmlspecialchars($TecId);
        $password = md5(htmlspecialchars($password));
        $ret = $this->getItem($TecId);
        if (count($ret)>0) {
            if ($ret['password'] === $password){
                return 1;   // 正确
            }else {
                return 0;  // 密码错误
            }
        }else {
            return -1;  // 账号不存在或错误。
        }
    }
}